package edu.hawaii.ics.pjdb.util;

import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.server.TServer;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TTransportFactory;

public class ThriftHelper {
    private static final TTransportFactory transportFactory = new TFramedTransport.Factory();
    private static final TProtocolFactory protocolFactory = new TCompactProtocol.Factory();

    public static final TTransportFactory getTransportFactory() {
        return transportFactory;
    }

    public static final TProtocolFactory getProtocolFactory() {
        return protocolFactory;
    }

    /**
     * Starts the specified server in a new thread. Returns the thread.
     * 
     * @param server
     * @return {@link Thread}
     */
    public static Thread startServer(final TServer server) {
        Thread serverThread = new Thread(new Runnable() {
            @Override
            public void run() {
                server.serve();
            }
        });

        serverThread.start();

        return serverThread;
    }
}